<template>
  <div>
    <Search :search="search" :reset="reset">
      <template v-slot:body>
        <el-form-item label="销售出库单" prop="fbillno">
          <el-input v-model="query.fbillno" name="fbillno" clearable />
        </el-form-item>
        <!-- <el-form-item label="采购订单号" prop="fbillno" maxlength="5">
          <el-input v-model="query.fbillno" name="fbillno" clearable />
        </el-form-item>
        <el-form-item label="供应商编码" prop="fsupplierid_number">
          <el-input v-model="query.fsupplierid_number" name="fsupplierid_number" clearable />
        </el-form-item>
        <el-form-item label="供应商名称" prop="fsupplierid_name">
          <el-input v-model="query.fsupplierid_name" name="fsupplierid_name" clearable />
        </el-form-item>
        <el-form-item label="单据状态" prop="fdocumentstatus">
          <el-select v-model="query.fdocumentstatus" placeholder="请选择" clearable>
            <el-option label="未审核" value="0" />
            <el-option label="审核" value="1" />
          </el-select>
        </el-form-item> -->
      </template>
    </Search>
    <div class="table-default" v-if="tableData">
      <!-- <Operate :show="open" /> -->
      <el-table :data="tableData" class="mt-3" v-loading="loading" border>
        <!-- <el-table-column prop="fseq" label="行号" /> -->
        <el-table-column prop="fbillno" label="销售出库单" width="250" />
        <el-table-column prop="fsaleorgid_number" label="销售组织编码" min-width="130" />
        <el-table-column prop="fsaleorgid_name" label="销售组织名称" width="150" />
        <el-table-column prop="incomingtype" label="组织关系" width="150" >
          <template #default="scope">
            <el-tag class="ml-2" type="warning" v-if="scope.row.incomingtype == '组织间销售出库'">{{scope.row.incomingtype}}</el-tag>
            <el-tag class="ml-2" type="success" v-else>{{scope.row.incomingtype}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="fcustomerid_number" label="客户编码" width="150" />
        <el-table-column prop="fcustomerid_name" label="客户名称" width="200" />
        <el-table-column prop="fqty" label="计划数量" width="100" />
        <el-table-column prop="fdocumentstatus" label="单据状态" min-width="120">
          <template #default="scope">
            <el-tag class="ml-2" type="warning" v-if="scope.row.fdocumentstatus == '0'">{{ formatFdocumentstatus[scope.row.fdocumentstatus] }}</el-tag>
            <el-tag class="ml-2" type="success" v-else>{{ formatFdocumentstatus[scope.row.fdocumentstatus] }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="writestate" label="回写状态" width="100" />
        <!-- <el-table-column prop="updated_at" label="更新时间" width="150" /> -->

        <el-table-column label="操作" width="100" fixed="right">
          <template #default="scope">
            <!-- <Update @click="open(scope.row.id)" />
            <Destroy @click="destroy(api, scope.row.id)" /> -->
            <router-link :to="{ path: '/Salesmanagement/outboundDetails', query: { id: `${scope.row.id}` } }">
              <Show />
            </router-link>
          </template>
        </el-table-column>
      </el-table>
      <Paginate />
    </div>
    <div class="table-default" v-else>
      <el-empty :image-size="200" />
    </div>
    <Dialog v-model="visible" :title="title" destroy-on-close>
      <Create @close="close(reset)" :primary="id" :api="api" />
    </Dialog>
  </div>
</template>

<script lang="ts" setup>
import { computed, onMounted } from 'vue'
import Create from './create.vue'
import { useGetList } from '/admin/composables/curd/useGetList'
import { useDestroy } from '/admin/composables/curd/useDestroy'
import { useOpen } from '/admin/composables/curd/useOpen'
import {setTableHeight} from '/admin/utils/setHeight.js'

const api = 'salesmanagement/Salesinterface'

const { data, query, search, reset, loading } = useGetList(api)
const { destroy, deleted } = useDestroy()
const { open, close, title, visible, id } = useOpen()

const tableData = computed(() => data.value?.data)

const  formatFdocumentstatus = {
  0:'未审核',
  1:'审核'
}

onMounted(() => {
  search()
  deleted(reset)
  setTableHeight('.table-default')

})
</script>

<style>
.el-table {
  height: 87%;
}
</style>
